package sequence.recorder;

import java.io.IOException;

import org.newdawn.slick.AppGameContainer;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Input;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.state.StateBasedGame;

import sequence.SequenceUtils;

class SequenceRecorderGame extends StateBasedGame {
	TrackList trackList = new TrackList();

	public SequenceRecorderGame() {
		super("Sequence recorder");
	}

	public TrackList getTrackList() {
		return trackList;
	}

	public static void main(String[] args) {
		try {
			SequenceRecorderGame game = new SequenceRecorderGame();
			game.getTrackList().newTrack(Input.KEY_SPACE, "space");
			game.getTrackList().newTrack(Input.KEY_1, "one");
			AppGameContainer container = new AppGameContainer(game);
			container.setDisplayMode(800, 600, false);
			container.start();
		} catch (SlickException e) {
			e.printStackTrace();
		}
	}

	@Override
	public void initStatesList(GameContainer container) throws SlickException {
		addState(new RecordingGameState(trackList));
	}

	@Override
	public boolean closeRequested() {
		try {
			for (Track track : trackList)
				SequenceUtils.save(track.getSequence());
		} catch (IOException e) {
			e.printStackTrace();
		}
		return super.closeRequested();
	}
}
